package com.cyl.game.demos.web.controller;

import com.cyl.game.demos.web.entity.Result;
import org.springframework.web.bind.annotation.*;
import java.util.List;

import javax.annotation.Resource;

import com.cyl.game.demos.web.entity.Hero;
import com.cyl.game.demos.web.service.HeroService;

@RestController
@RequestMapping("/hero")
public class HeroController {
    @Resource
    private HeroService heroDesignService;

    // 添加英雄设计
    @PostMapping("/add")
    public Result addHeroDesign(@RequestBody Hero heroDesign) {
        int result = heroDesignService.addHeroDesign(heroDesign);
        if (result > 0) {
            return Result.success("英雄设计添加成功") ;
        } else {
            return Result.failure(201,"英雄设计添加失败");
        }
    }

    // 根据用户ID查询该用户的所有英雄设计信息
    @GetMapping("/user/{user_id}")
    public Result<List<Hero>> getHeroDesignsByUserId(@PathVariable("user_id") Integer user_id) {
        return Result.success(heroDesignService.getHeroDesignsByUserId(user_id));
    }

    // 修改英雄设计信息
    @PutMapping("/update")
    public Result updateHeroDesign(@RequestBody Hero heroDesign) {
        int result = heroDesignService.updateHeroDesign(heroDesign);
        if (result > 0) {
            return Result.success("英雄设计更新成功") ;
        } else {
            return Result.failure(202,"英雄设计更新失败");
        }
    }

    // 删除英雄设计信息
    @DeleteMapping("/{hero_id}")
    public Result deleteHeroDesign(@PathVariable("hero_id") Integer hero_id) {
        int result = heroDesignService.deleteHeroDesign(hero_id);
        if (result > 0) {
            return Result.success("英雄设计删除成功") ;
        } else {
            return Result.failure(203,"英雄设计删除失败");
        }
    }
}